import * as actionTypes from './actionTypes'
import {getTopBanners, getHotRecommends,getNewAlbums} from '@/service/recommend'
import { getToplistDetail } from '@/service/toplist'

/**
 * @description 轮播图Action
 * @param {*} res 
 */
export const changeTopBannerAction = res =>({
  type:actionTypes.CHANGE_TOP_BANNER,
  topBanners:res.banners
})

export const changeHotRecommendAction = res =>({
  type:actionTypes.CHANGE_HOT_RECOMMEND,
  hotRecommends:res.result
})

export const changeNewAlbumsAction = res =>({
  type:actionTypes.CHANGE_NEW_ALBUMS,
  newAlbums:res.albums,
})



// 飙升榜单Action
export const changeUpRanking = res => ({
  type: actionTypes.CHANGE_UP_RANKING,
  upRanking: res.playlist,
})
// 新歌榜单Action
export const changeNewRanking = res => ({
  type: actionTypes.CHANGE_NEW_RANKING,
  newRanking: res.playlist,
})
// 原创榜单Action
export const changeOriginRanking = res => ({
  type: actionTypes.CHANGE_ORIGIN_RANKING,
  originRanking: res.playlist,
})



/**
 * 轮播图network request
 */
export const getTopBannersAction=()=>{
  return dispatch=>{
    getTopBanners().then((res)=>{
      dispatch(changeTopBannerAction(res))
    })
  }
}



// 热门推荐network request
export const getHostBannersAction = limit => {
  return dispatch => {
    getHotRecommends(limit).then(res => {
      dispatch(changeHotRecommendAction(res))
    })
  }
}

// 新碟上架network request
export const getNewAlbumsAction = () => {
  return dispatch => {
    getNewAlbums().then(res => {
      dispatch(changeNewAlbumsAction(res))
    })
  }
}

// 新碟上架network request
export const getTopListAction = (idx) => {
  return dispatch => {
    getToplistDetail(idx).then(res =>{
      switch (idx){
        case 19723756:
          dispatch(changeUpRanking(res))
          break
        case 3779629:
          dispatch(changeNewRanking(res))
          break
        case 2884035:
          dispatch(changeOriginRanking(res))
          break
        default:
      }
    })
  }
}


